package chapter03.Demo3;
class  Student{
    String id;//学号
    private String name;//私有属性,姓名
    private int age;//年龄
    private  int gender;//性别 0男 1女

    /**
     * Student 类的构造方法
     */
    public Student(String s){
        name=s;
    }

    public Student(String s,int g,int a) {
        name=s;
        gender=g;
        age=a;
    }

    public void print() {//公有的方法
        System.out.println("id:"+id+";name"+name+";age:"+age);
    }

    public String getName(){
        return name;
    }
    public void setName(String s){
        name=s;
    }

    public void setAge(int n) {
        if (n<=0){
            System.out.println("年龄非法");
        }
        if (n>=200){
            System.out.println("年龄超出200岁!非法");
        }
        age=n;
    }

    public void setGender(String s) {
        if (s.equals('男')) {
            gender=0;
        } else  {
            gender=1;
        }
    }

    public String setGender() {
        String g;
        if (gender==0){
            g  = "男";
        }else  {
            g = "女";
        }
        return g;
    }
}
public class Demo3 {
    public static void main(String[] args) {
        //构造函数
        Student stu1= new Student("蘑菇头");
        System.out.println(stu1.getName());
        Student stu2=new Student("蘑菇头",0,20);
    }
}
